﻿namespace NEvoWeb.Modules.NB_Store
{
    using DotNetNuke.Entities.Portals;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Text;
    using System.Web;
    using System.Xml;

    public abstract class XMLProvider : IHttpHandler
    {
        protected XMLProvider()
        {
        }

        public void ProcessRequest(HttpContext context)
        {
            if ((context.Request.QueryString["action"] != null) && (context.Request.QueryString["action"].ToLower() == "addtorelated"))
            {
                try
                {
                    string productID = context.Request.QueryString["prodID"];
                    string relatedProductID = context.Request.QueryString["relID"];
                    RelatedProducts.AddProduct(PortalController.GetCurrentPortalSettings().PortalId, productID, relatedProductID);
                    context.Response.Write("done");
                }
                catch (Exception exception1)
                {
                    ProjectData.SetProjectError(exception1);
                    Exception exception = exception1;
                    context.Response.Write(exception.Message);
                    ProjectData.ClearProjectError();
                }
            }
            else
            {
                string str2 = SharedFunctions.getURLParam(context, "key");
                string str5 = SharedFunctions.getURLParam(context, "ProdID");
                string str6 = SharedFunctions.getURLParam(context, "ProdRef");
                string str = SharedFunctions.getURLParam(context, "CatID");
                string str4 = SharedFunctions.getURLParam(context, "PortalID");
                string str3 = SharedFunctions.getURLParam(context, "Lang");
                ProductController controller = new ProductController();
                Export export = new Export();
                string feederReportText = SharedFunctions.GetFeederReportText(context, true);
                if (feederReportText != "")
                {
                    XmlDataDocument document = new XmlDataDocument();
                    document.LoadXml(feederReportText);
                    context.Response.ContentType = "text/xml";
                    context.Response.ContentEncoding = Encoding.UTF8;
                    context.Response.Cache.SetAllowResponseInBrowserHistory(true);
                    document.Save(context.Response.OutputStream);
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return true;
            }
        }

        
    }
}

